﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Data;
using System.Globalization;

namespace BadHabit.WPFTools.Converters {

    [ValueConversion(typeof(object), typeof(Int16))]
    public class LocalizeConverter : IValueConverter {

        public static System.Resources.ResourceManager ResourceManager { get; set; }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {

            if (ResourceManager == null)
                return value;

            if (value == null)
                return null;
            object loc = ResourceManager.GetObject(value.ToString());
            if (loc == null)
                return value.ToString();
            return loc.ToString();
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            throw new NotSupportedException();
        }
    }
}
